package cn.donting.jme.editor.scene.wrapper;

import cn.donting.jme.editor.scene.Wrapper;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import lombok.Getter;
import lombok.Setter;

import java.io.IOException;

public class DirectionalLightWrapper extends Wrapper<DirectionalLight> {
    @Getter
    @Setter
    private Quaternion rotation = new Quaternion();

    public DirectionalLightWrapper() {
    }

    @Override
    public void initValue(DirectionalLight light) {
        super.initValue(light);
        rotation.lookAt(light.getDirection(), Vector3f.UNIT_Y);
    }

    @Override
    public void read(JmeImporter im) throws IOException {
        super.read(im);
        InputCapsule capsule = im.getCapsule(this);
        rotation = (Quaternion) capsule.readSavable("rotation", null);
    }

    @Override
    public void write(JmeExporter ex) throws IOException {
        super.write(ex);
        OutputCapsule capsule = ex.getCapsule(this);
        capsule.write(rotation, "rotation", null);
    }
}
